package cn.zs.supply.common.core.security.simple;

import cn.zs.supply.common.constants.enums.PubErrCode;
import cn.zs.supply.common.utils.ResponseUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class LoginFailureHandler extends SimpleUrlAuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        JSONObject responseJson=new JSONObject();
        responseJson.put("code", PubErrCode.FAIL_LOGINED.getCode());
        responseJson.put("errcode",PubErrCode.FAIL_LOGINED.getCode());
        responseJson.put("msg",PubErrCode.FAIL_LOGINED.getMsg());
        responseJson.put("success", "true");
        ResponseUtil.setResponse(response,responseJson);
    }
}
